<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${login_title}+'-登录'"></title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="智能停车场管理平台">
    <meta name="description" content="智能停车场管理平台">
    <link rel="shortcut icon" th:href="@{/images/favicon.ico}" type="image/x-icon"/>
    <link rel="stylesheet" th:href="@{/css/login_new.css}"/>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}"/>
</head>
<body background="images/login.svg">
<form class="layui-form" action="javascript:void(0);">
    <div class="layui-form-item">
        <img class="logo" th:src="@{images/logo.png}" />
        <div class="title">Smart-Parking</div>
        <div class="desc" th:text="${login_title}"/>
    </div>
    <div class="layui-form-item">
        <input name="username" type="text" placeholder="账 户" value="admin" hover class="layui-input"  />
    </div>
    <div class="layui-form-item">
        <input name="password" type="password" placeholder="密 码" value="admin" hover class="layui-input"  />
    </div>
    <div class="layui-form-item">
        <input placeholder="验证码" name="verCode" hover class="code layui-input layui-input-inline"  />
        <img th:src="@{/sys/captcha}" class="codeImage" id="captchaImage"/>
    </div>
    <div class="layui-form-item">
        <input type="checkbox" name="rememberMe" value="true" title="记住密码" lay-skin="primary">
    </div>
    <div class="layui-form-item">
        <button class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
            登 入
        </button>
    </div>
</form>
<script th:src="@{/lib/layui/layui.js}"></script>
<script>
 layui.use(['form',"okUtils", "okLayer"], function() {
    var form = layui.form;
    var $ = layui.jquery;
    var okUtils = layui.okUtils;
    var okLayer = layui.okLayer;
    var captchaPath = "/sys/captcha";
    form.on('submit(login)', function(data){
        $.ajax({
            url:'/sys/login',
            data:data.field,
            type:"post",
            dataType:'json',
            success:function(result){
                if(result.code==0){
                    okLayer.msg.greenTick(result.msg, function () {
                        sessionStorage.setItem('username', $("#username").val());
                        window.location = "index.html";
                    });
                }else if(result.code==400){
                    okLayer.msg.redCross(result.msg)
                    document.getElementById("captchaImage").src= captchaPath + "?" + Math.random();
                }
            }
        });
        return false;
    });
    $("#captchaImage").click(function(){
        document.getElementById("captchaImage").src= captchaPath + "?" + Math.random();
    })
    setInterval(function(){
        document.getElementById("captchaImage").src= captchaPath + "?" + Math.random();
    },30 * 1000);
});
</script>
<script >
window.onload=function(){
    if (window != top) {
        alert("您的账号在另一台设备上登录，若非本人操作，请立即修改密码")
        top.location.href = location.href;
    }
}
</script>
</body>
</html>